﻿using BarManager.Core.BusinessRules.Interfaces.Specification;
using BarManager.Core.DomainService;
using BarManager.Core.Entity;
using System.Collections.Generic;

namespace BarManager.Core.BusinessRules.Specification
{
    public class CargoDeleteSpecification : BaseSpecification<Cargo>, ICargoSpecification
    {  
        private Cargo Cargo = null;
        private int CountEmpleados = 0;
               
        public CargoDeleteSpecification(ICargoRepository repository)
            : base(repository)
        {
        }

        public override bool IsSatisfiedBy(Cargo entity)
        {
            Cargo = BaseRepository.Get(x => x.Id == entity.Id);
            if (Cargo != null && Cargo.EmpleadoList != null)
                CountEmpleados = Cargo.EmpleadoList.Count;

            return (CountEmpleados == 0);
        }

        public override IEnumerable<string> GetErrorMessage()
        {
            if (CountEmpleados > 0) yield return "El cargo no puede ser eliminado, porque está asignado a empleados";
            yield break;
        }
    }
}
